﻿using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace JGSY.CMS.LowCode.Platform.Migrations
{
    /// <inheritdoc />
    public partial class DatabaseTableNameStandardization : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_LoginHistories_users_UserId",
                table: "LoginHistories");

            migrationBuilder.DropForeignKey(
                name: "FK_Publishes_content_items_ContentId",
                table: "Publishes");

            migrationBuilder.DropForeignKey(
                name: "FK_Publishes_users_UserId",
                table: "Publishes");

            migrationBuilder.DropForeignKey(
                name: "FK_RolePermissions_permissions_PermissionId",
                table: "RolePermissions");

            migrationBuilder.DropForeignKey(
                name: "FK_RolePermissions_roles_RoleId",
                table: "RolePermissions");

            migrationBuilder.DropForeignKey(
                name: "FK_UserDevices_users_UserId",
                table: "UserDevices");

            migrationBuilder.DropForeignKey(
                name: "FK_UserRoles_roles_RoleId",
                table: "UserRoles");

            migrationBuilder.DropForeignKey(
                name: "FK_UserRoles_users_UserId",
                table: "UserRoles");

            migrationBuilder.DropForeignKey(
                name: "FK_workflow_instances_Workflows_WorkflowId",
                table: "workflow_instances");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Workflows",
                table: "Workflows");

            migrationBuilder.DropIndex(
                name: "IX_workflow_tasks_AssigneeId",
                table: "workflow_tasks");

            migrationBuilder.DropIndex(
                name: "IX_workflow_instances_WorkflowId",
                table: "workflow_instances");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Publishes",
                table: "Publishes");

            migrationBuilder.DropIndex(
                name: "IX_media_files_CreatedBy",
                table: "media_files");

            migrationBuilder.DropIndex(
                name: "IX_form_submissions_FormId",
                table: "form_submissions");

            migrationBuilder.DropIndex(
                name: "IX_categories_ParentId",
                table: "categories");

            migrationBuilder.DropPrimaryKey(
                name: "PK_UserRoles",
                table: "UserRoles");

            migrationBuilder.DropPrimaryKey(
                name: "PK_UserDevices",
                table: "UserDevices");

            migrationBuilder.DropPrimaryKey(
                name: "PK_TwoFactors",
                table: "TwoFactors");

            migrationBuilder.DropPrimaryKey(
                name: "PK_SystemSettings",
                table: "SystemSettings");

            migrationBuilder.DropPrimaryKey(
                name: "PK_SecurityLogs",
                table: "SecurityLogs");

            migrationBuilder.DropPrimaryKey(
                name: "PK_SecurityEvents",
                table: "SecurityEvents");

            migrationBuilder.DropPrimaryKey(
                name: "PK_RolePermissions",
                table: "RolePermissions");

            migrationBuilder.DropPrimaryKey(
                name: "PK_RiskAssessments",
                table: "RiskAssessments");

            migrationBuilder.DropPrimaryKey(
                name: "PK_OperationLogs",
                table: "OperationLogs");

            migrationBuilder.DropPrimaryKey(
                name: "PK_LoginHistories",
                table: "LoginHistories");

            migrationBuilder.DropIndex(
                name: "IX_LoginHistories_UserId",
                table: "LoginHistories");

            migrationBuilder.DropPrimaryKey(
                name: "PK_ExceptionLogs",
                table: "ExceptionLogs");

            migrationBuilder.DropPrimaryKey(
                name: "PK_AuditLogs",
                table: "AuditLogs");

            migrationBuilder.RenameTable(
                name: "Workflows",
                newName: "workflows");

            migrationBuilder.RenameTable(
                name: "Publishes",
                newName: "publishes");

            migrationBuilder.RenameTable(
                name: "UserRoles",
                newName: "user_roles");

            migrationBuilder.RenameTable(
                name: "UserDevices",
                newName: "user_devices");

            migrationBuilder.RenameTable(
                name: "TwoFactors",
                newName: "two_factors");

            migrationBuilder.RenameTable(
                name: "SystemSettings",
                newName: "system_settings");

            migrationBuilder.RenameTable(
                name: "SecurityLogs",
                newName: "security_logs");

            migrationBuilder.RenameTable(
                name: "SecurityEvents",
                newName: "security_events");

            migrationBuilder.RenameTable(
                name: "RolePermissions",
                newName: "role_permissions");

            migrationBuilder.RenameTable(
                name: "RiskAssessments",
                newName: "risk_assessments");

            migrationBuilder.RenameTable(
                name: "OperationLogs",
                newName: "operation_logs");

            migrationBuilder.RenameTable(
                name: "LoginHistories",
                newName: "login_histories");

            migrationBuilder.RenameTable(
                name: "ExceptionLogs",
                newName: "exception_logs");

            migrationBuilder.RenameTable(
                name: "AuditLogs",
                newName: "audit_logs");

            migrationBuilder.RenameIndex(
                name: "IX_workflow_versions_WorkflowId_Version",
                table: "workflow_versions",
                newName: "ix_workflow_versions_workflow_version_unique");

            migrationBuilder.RenameIndex(
                name: "IX_users_Username",
                table: "users",
                newName: "ix_users_username_unique");

            migrationBuilder.RenameIndex(
                name: "IX_users_Email",
                table: "users",
                newName: "ix_users_email_unique");

            migrationBuilder.RenameIndex(
                name: "IX_Publishes_UserId",
                table: "publishes",
                newName: "IX_publishes_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_Publishes_ContentId",
                table: "publishes",
                newName: "IX_publishes_ContentId");

            migrationBuilder.RenameIndex(
                name: "IX_permission_route_mappings_Priority",
                table: "permission_route_mappings",
                newName: "ix_permission_route_mappings_priority");

            migrationBuilder.RenameIndex(
                name: "IX_permission_route_mappings_Group",
                table: "permission_route_mappings",
                newName: "ix_permission_route_mappings_group");

            migrationBuilder.RenameIndex(
                name: "IX_permission_route_mappings_Path_Method",
                table: "permission_route_mappings",
                newName: "ix_permission_route_mappings_path_method_unique");

            migrationBuilder.RenameIndex(
                name: "IX_permission_route_mappings_IsActive",
                table: "permission_route_mappings",
                newName: "ix_permission_route_mappings_active");

            migrationBuilder.RenameIndex(
                name: "IX_pages_Slug",
                table: "pages",
                newName: "ix_pages_slug_unique");

            migrationBuilder.RenameIndex(
                name: "IX_monitor_user_interactions_Timestamp",
                table: "monitor_user_interactions",
                newName: "ix_monitor_user_interactions_timestamp");

            migrationBuilder.RenameIndex(
                name: "IX_monitor_user_interactions_SessionId",
                table: "monitor_user_interactions",
                newName: "ix_monitor_user_interactions_session_id");

            migrationBuilder.RenameIndex(
                name: "IX_monitor_user_interactions_InteractionType",
                table: "monitor_user_interactions",
                newName: "ix_monitor_user_interactions_interaction_type");

            migrationBuilder.RenameIndex(
                name: "IX_monitor_session_summary_UserId",
                table: "monitor_session_summary",
                newName: "ix_monitor_session_summary_user_id");

            migrationBuilder.RenameIndex(
                name: "IX_monitor_session_summary_SessionStart",
                table: "monitor_session_summary",
                newName: "ix_monitor_session_summary_session_start");

            migrationBuilder.RenameIndex(
                name: "IX_monitor_session_summary_SessionId",
                table: "monitor_session_summary",
                newName: "ix_monitor_session_summary_session_id_unique");

            migrationBuilder.RenameIndex(
                name: "IX_monitor_performance_metrics_Timestamp",
                table: "monitor_performance_metrics",
                newName: "ix_monitor_performance_metrics_timestamp");

            migrationBuilder.RenameIndex(
                name: "IX_monitor_performance_metrics_SessionId",
                table: "monitor_performance_metrics",
                newName: "ix_monitor_performance_metrics_session_id");

            migrationBuilder.RenameIndex(
                name: "IX_monitor_performance_metrics_MetricName_Timestamp",
                table: "monitor_performance_metrics",
                newName: "ix_monitor_performance_metrics_name_timestamp");

            migrationBuilder.RenameIndex(
                name: "IX_monitor_performance_metrics_MetricName",
                table: "monitor_performance_metrics",
                newName: "ix_monitor_performance_metrics_metric_name");

            migrationBuilder.RenameIndex(
                name: "IX_monitor_error_logs_Severity",
                table: "monitor_error_logs",
                newName: "ix_monitor_error_logs_severity");

            migrationBuilder.RenameIndex(
                name: "IX_monitor_error_logs_Fingerprint",
                table: "monitor_error_logs",
                newName: "ix_monitor_error_logs_fingerprint");

            migrationBuilder.RenameIndex(
                name: "IX_monitor_error_logs_SessionId",
                table: "monitor_error_logs",
                newName: "ix_monitor_error_logs_session_id");

            migrationBuilder.RenameIndex(
                name: "IX_monitor_error_logs_ErrorType",
                table: "monitor_error_logs",
                newName: "ix_monitor_error_logs_error_type");

            migrationBuilder.RenameIndex(
                name: "IX_monitor_error_logs_CreatedAt",
                table: "monitor_error_logs",
                newName: "ix_monitor_error_logs_created_at");

            migrationBuilder.RenameIndex(
                name: "IX_UserRoles_RoleId",
                table: "user_roles",
                newName: "ix_user_roles_role_id");

            migrationBuilder.RenameIndex(
                name: "IX_UserDevices_UserId",
                table: "user_devices",
                newName: "IX_user_devices_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_RolePermissions_PermissionId",
                table: "role_permissions",
                newName: "ix_role_permissions_permission_id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_workflows",
                table: "workflows",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_publishes",
                table: "publishes",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_user_roles",
                table: "user_roles",
                columns: new[] { "UserId", "RoleId" });

            migrationBuilder.AddPrimaryKey(
                name: "PK_user_devices",
                table: "user_devices",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_two_factors",
                table: "two_factors",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_system_settings",
                table: "system_settings",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_security_logs",
                table: "security_logs",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_security_events",
                table: "security_events",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_role_permissions",
                table: "role_permissions",
                columns: new[] { "RoleId", "PermissionId" });

            migrationBuilder.AddPrimaryKey(
                name: "PK_risk_assessments",
                table: "risk_assessments",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_operation_logs",
                table: "operation_logs",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_login_histories",
                table: "login_histories",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_exception_logs",
                table: "exception_logs",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_audit_logs",
                table: "audit_logs",
                column: "Id");

            migrationBuilder.CreateIndex(
                name: "ix_workflow_tasks_assignee_status",
                table: "workflow_tasks",
                columns: new[] { "AssigneeId", "Status" });

            migrationBuilder.CreateIndex(
                name: "ix_workflow_instances_workflow_status",
                table: "workflow_instances",
                columns: new[] { "WorkflowId", "Status" });

            migrationBuilder.CreateIndex(
                name: "ix_users_status_created",
                table: "users",
                columns: new[] { "Status", "CreatedAt" });

            migrationBuilder.CreateIndex(
                name: "ix_pages_status_created",
                table: "pages",
                columns: new[] { "Status", "CreatedAt" });

            migrationBuilder.CreateIndex(
                name: "ix_monitor_error_logs_type_timestamp",
                table: "monitor_error_logs",
                columns: new[] { "ErrorType", "Timestamp" });

            migrationBuilder.CreateIndex(
                name: "ix_media_files_created_by_at",
                table: "media_files",
                columns: new[] { "CreatedBy", "CreatedAt" });

            migrationBuilder.CreateIndex(
                name: "ix_media_files_mime_type",
                table: "media_files",
                column: "MimeType");

            migrationBuilder.CreateIndex(
                name: "ix_form_submissions_form_submit_time",
                table: "form_submissions",
                columns: new[] { "FormId", "SubmitTime" });

            migrationBuilder.CreateIndex(
                name: "ix_categories_parent_sort",
                table: "categories",
                columns: new[] { "ParentId", "SortOrder" });

            migrationBuilder.CreateIndex(
                name: "ix_categories_slug_unique",
                table: "categories",
                column: "Slug",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "ix_articles_slug_unique",
                table: "articles",
                column: "Slug",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "ix_articles_status_published",
                table: "articles",
                columns: new[] { "Status", "PublishedAt" });

            migrationBuilder.CreateIndex(
                name: "ix_user_roles_user_id",
                table: "user_roles",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "ix_security_events_type_created",
                table: "security_events",
                columns: new[] { "EventType", "CreatedAt" });

            migrationBuilder.CreateIndex(
                name: "ix_security_events_user",
                table: "security_events",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "ix_role_permissions_role_id",
                table: "role_permissions",
                column: "RoleId");

            migrationBuilder.CreateIndex(
                name: "ix_login_histories_ip",
                table: "login_histories",
                column: "IpAddress");

            migrationBuilder.CreateIndex(
                name: "ix_login_histories_user_created",
                table: "login_histories",
                columns: new[] { "UserId", "CreatedAt" });

            migrationBuilder.CreateIndex(
                name: "ix_audit_logs_type",
                table: "audit_logs",
                column: "Type");

            migrationBuilder.CreateIndex(
                name: "ix_audit_logs_user_timestamp",
                table: "audit_logs",
                columns: new[] { "UserId", "Timestamp" });

            migrationBuilder.AddForeignKey(
                name: "FK_login_histories_users_UserId",
                table: "login_histories",
                column: "UserId",
                principalTable: "users",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_publishes_content_items_ContentId",
                table: "publishes",
                column: "ContentId",
                principalTable: "content_items",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_publishes_users_UserId",
                table: "publishes",
                column: "UserId",
                principalTable: "users",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_role_permissions_permissions_PermissionId",
                table: "role_permissions",
                column: "PermissionId",
                principalTable: "permissions",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_role_permissions_roles_RoleId",
                table: "role_permissions",
                column: "RoleId",
                principalTable: "roles",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_user_devices_users_UserId",
                table: "user_devices",
                column: "UserId",
                principalTable: "users",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_user_roles_roles_RoleId",
                table: "user_roles",
                column: "RoleId",
                principalTable: "roles",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_user_roles_users_UserId",
                table: "user_roles",
                column: "UserId",
                principalTable: "users",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_workflow_instances_workflows_WorkflowId",
                table: "workflow_instances",
                column: "WorkflowId",
                principalTable: "workflows",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_login_histories_users_UserId",
                table: "login_histories");

            migrationBuilder.DropForeignKey(
                name: "FK_publishes_content_items_ContentId",
                table: "publishes");

            migrationBuilder.DropForeignKey(
                name: "FK_publishes_users_UserId",
                table: "publishes");

            migrationBuilder.DropForeignKey(
                name: "FK_role_permissions_permissions_PermissionId",
                table: "role_permissions");

            migrationBuilder.DropForeignKey(
                name: "FK_role_permissions_roles_RoleId",
                table: "role_permissions");

            migrationBuilder.DropForeignKey(
                name: "FK_user_devices_users_UserId",
                table: "user_devices");

            migrationBuilder.DropForeignKey(
                name: "FK_user_roles_roles_RoleId",
                table: "user_roles");

            migrationBuilder.DropForeignKey(
                name: "FK_user_roles_users_UserId",
                table: "user_roles");

            migrationBuilder.DropForeignKey(
                name: "FK_workflow_instances_workflows_WorkflowId",
                table: "workflow_instances");

            migrationBuilder.DropPrimaryKey(
                name: "PK_workflows",
                table: "workflows");

            migrationBuilder.DropIndex(
                name: "ix_workflow_tasks_assignee_status",
                table: "workflow_tasks");

            migrationBuilder.DropIndex(
                name: "ix_workflow_instances_workflow_status",
                table: "workflow_instances");

            migrationBuilder.DropIndex(
                name: "ix_users_status_created",
                table: "users");

            migrationBuilder.DropPrimaryKey(
                name: "PK_publishes",
                table: "publishes");

            migrationBuilder.DropIndex(
                name: "ix_pages_status_created",
                table: "pages");

            migrationBuilder.DropIndex(
                name: "ix_monitor_error_logs_type_timestamp",
                table: "monitor_error_logs");

            migrationBuilder.DropIndex(
                name: "ix_media_files_created_by_at",
                table: "media_files");

            migrationBuilder.DropIndex(
                name: "ix_media_files_mime_type",
                table: "media_files");

            migrationBuilder.DropIndex(
                name: "ix_form_submissions_form_submit_time",
                table: "form_submissions");

            migrationBuilder.DropIndex(
                name: "ix_categories_parent_sort",
                table: "categories");

            migrationBuilder.DropIndex(
                name: "ix_categories_slug_unique",
                table: "categories");

            migrationBuilder.DropIndex(
                name: "ix_articles_slug_unique",
                table: "articles");

            migrationBuilder.DropIndex(
                name: "ix_articles_status_published",
                table: "articles");

            migrationBuilder.DropPrimaryKey(
                name: "PK_user_roles",
                table: "user_roles");

            migrationBuilder.DropIndex(
                name: "ix_user_roles_user_id",
                table: "user_roles");

            migrationBuilder.DropPrimaryKey(
                name: "PK_user_devices",
                table: "user_devices");

            migrationBuilder.DropPrimaryKey(
                name: "PK_two_factors",
                table: "two_factors");

            migrationBuilder.DropPrimaryKey(
                name: "PK_system_settings",
                table: "system_settings");

            migrationBuilder.DropPrimaryKey(
                name: "PK_security_logs",
                table: "security_logs");

            migrationBuilder.DropPrimaryKey(
                name: "PK_security_events",
                table: "security_events");

            migrationBuilder.DropIndex(
                name: "ix_security_events_type_created",
                table: "security_events");

            migrationBuilder.DropIndex(
                name: "ix_security_events_user",
                table: "security_events");

            migrationBuilder.DropPrimaryKey(
                name: "PK_role_permissions",
                table: "role_permissions");

            migrationBuilder.DropIndex(
                name: "ix_role_permissions_role_id",
                table: "role_permissions");

            migrationBuilder.DropPrimaryKey(
                name: "PK_risk_assessments",
                table: "risk_assessments");

            migrationBuilder.DropPrimaryKey(
                name: "PK_operation_logs",
                table: "operation_logs");

            migrationBuilder.DropPrimaryKey(
                name: "PK_login_histories",
                table: "login_histories");

            migrationBuilder.DropIndex(
                name: "ix_login_histories_ip",
                table: "login_histories");

            migrationBuilder.DropIndex(
                name: "ix_login_histories_user_created",
                table: "login_histories");

            migrationBuilder.DropPrimaryKey(
                name: "PK_exception_logs",
                table: "exception_logs");

            migrationBuilder.DropPrimaryKey(
                name: "PK_audit_logs",
                table: "audit_logs");

            migrationBuilder.DropIndex(
                name: "ix_audit_logs_type",
                table: "audit_logs");

            migrationBuilder.DropIndex(
                name: "ix_audit_logs_user_timestamp",
                table: "audit_logs");

            migrationBuilder.RenameTable(
                name: "workflows",
                newName: "Workflows");

            migrationBuilder.RenameTable(
                name: "publishes",
                newName: "Publishes");

            migrationBuilder.RenameTable(
                name: "user_roles",
                newName: "UserRoles");

            migrationBuilder.RenameTable(
                name: "user_devices",
                newName: "UserDevices");

            migrationBuilder.RenameTable(
                name: "two_factors",
                newName: "TwoFactors");

            migrationBuilder.RenameTable(
                name: "system_settings",
                newName: "SystemSettings");

            migrationBuilder.RenameTable(
                name: "security_logs",
                newName: "SecurityLogs");

            migrationBuilder.RenameTable(
                name: "security_events",
                newName: "SecurityEvents");

            migrationBuilder.RenameTable(
                name: "role_permissions",
                newName: "RolePermissions");

            migrationBuilder.RenameTable(
                name: "risk_assessments",
                newName: "RiskAssessments");

            migrationBuilder.RenameTable(
                name: "operation_logs",
                newName: "OperationLogs");

            migrationBuilder.RenameTable(
                name: "login_histories",
                newName: "LoginHistories");

            migrationBuilder.RenameTable(
                name: "exception_logs",
                newName: "ExceptionLogs");

            migrationBuilder.RenameTable(
                name: "audit_logs",
                newName: "AuditLogs");

            migrationBuilder.RenameIndex(
                name: "ix_workflow_versions_workflow_version_unique",
                table: "workflow_versions",
                newName: "IX_workflow_versions_WorkflowId_Version");

            migrationBuilder.RenameIndex(
                name: "ix_users_username_unique",
                table: "users",
                newName: "IX_users_Username");

            migrationBuilder.RenameIndex(
                name: "ix_users_email_unique",
                table: "users",
                newName: "IX_users_Email");

            migrationBuilder.RenameIndex(
                name: "IX_publishes_UserId",
                table: "Publishes",
                newName: "IX_Publishes_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_publishes_ContentId",
                table: "Publishes",
                newName: "IX_Publishes_ContentId");

            migrationBuilder.RenameIndex(
                name: "ix_permission_route_mappings_priority",
                table: "permission_route_mappings",
                newName: "IX_permission_route_mappings_Priority");

            migrationBuilder.RenameIndex(
                name: "ix_permission_route_mappings_group",
                table: "permission_route_mappings",
                newName: "IX_permission_route_mappings_Group");

            migrationBuilder.RenameIndex(
                name: "ix_permission_route_mappings_path_method_unique",
                table: "permission_route_mappings",
                newName: "IX_permission_route_mappings_Path_Method");

            migrationBuilder.RenameIndex(
                name: "ix_permission_route_mappings_active",
                table: "permission_route_mappings",
                newName: "IX_permission_route_mappings_IsActive");

            migrationBuilder.RenameIndex(
                name: "ix_pages_slug_unique",
                table: "pages",
                newName: "IX_pages_Slug");

            migrationBuilder.RenameIndex(
                name: "ix_monitor_user_interactions_timestamp",
                table: "monitor_user_interactions",
                newName: "IX_monitor_user_interactions_Timestamp");

            migrationBuilder.RenameIndex(
                name: "ix_monitor_user_interactions_session_id",
                table: "monitor_user_interactions",
                newName: "IX_monitor_user_interactions_SessionId");

            migrationBuilder.RenameIndex(
                name: "ix_monitor_user_interactions_interaction_type",
                table: "monitor_user_interactions",
                newName: "IX_monitor_user_interactions_InteractionType");

            migrationBuilder.RenameIndex(
                name: "ix_monitor_session_summary_user_id",
                table: "monitor_session_summary",
                newName: "IX_monitor_session_summary_UserId");

            migrationBuilder.RenameIndex(
                name: "ix_monitor_session_summary_session_start",
                table: "monitor_session_summary",
                newName: "IX_monitor_session_summary_SessionStart");

            migrationBuilder.RenameIndex(
                name: "ix_monitor_session_summary_session_id_unique",
                table: "monitor_session_summary",
                newName: "IX_monitor_session_summary_SessionId");

            migrationBuilder.RenameIndex(
                name: "ix_monitor_performance_metrics_timestamp",
                table: "monitor_performance_metrics",
                newName: "IX_monitor_performance_metrics_Timestamp");

            migrationBuilder.RenameIndex(
                name: "ix_monitor_performance_metrics_session_id",
                table: "monitor_performance_metrics",
                newName: "IX_monitor_performance_metrics_SessionId");

            migrationBuilder.RenameIndex(
                name: "ix_monitor_performance_metrics_name_timestamp",
                table: "monitor_performance_metrics",
                newName: "IX_monitor_performance_metrics_MetricName_Timestamp");

            migrationBuilder.RenameIndex(
                name: "ix_monitor_performance_metrics_metric_name",
                table: "monitor_performance_metrics",
                newName: "IX_monitor_performance_metrics_MetricName");

            migrationBuilder.RenameIndex(
                name: "ix_monitor_error_logs_severity",
                table: "monitor_error_logs",
                newName: "IX_monitor_error_logs_Severity");

            migrationBuilder.RenameIndex(
                name: "ix_monitor_error_logs_fingerprint",
                table: "monitor_error_logs",
                newName: "IX_monitor_error_logs_Fingerprint");

            migrationBuilder.RenameIndex(
                name: "ix_monitor_error_logs_session_id",
                table: "monitor_error_logs",
                newName: "IX_monitor_error_logs_SessionId");

            migrationBuilder.RenameIndex(
                name: "ix_monitor_error_logs_error_type",
                table: "monitor_error_logs",
                newName: "IX_monitor_error_logs_ErrorType");

            migrationBuilder.RenameIndex(
                name: "ix_monitor_error_logs_created_at",
                table: "monitor_error_logs",
                newName: "IX_monitor_error_logs_CreatedAt");

            migrationBuilder.RenameIndex(
                name: "ix_user_roles_role_id",
                table: "UserRoles",
                newName: "IX_UserRoles_RoleId");

            migrationBuilder.RenameIndex(
                name: "IX_user_devices_UserId",
                table: "UserDevices",
                newName: "IX_UserDevices_UserId");

            migrationBuilder.RenameIndex(
                name: "ix_role_permissions_permission_id",
                table: "RolePermissions",
                newName: "IX_RolePermissions_PermissionId");

            migrationBuilder.AddPrimaryKey(
                name: "PK_Workflows",
                table: "Workflows",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_Publishes",
                table: "Publishes",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_UserRoles",
                table: "UserRoles",
                columns: new[] { "UserId", "RoleId" });

            migrationBuilder.AddPrimaryKey(
                name: "PK_UserDevices",
                table: "UserDevices",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_TwoFactors",
                table: "TwoFactors",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_SystemSettings",
                table: "SystemSettings",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_SecurityLogs",
                table: "SecurityLogs",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_SecurityEvents",
                table: "SecurityEvents",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_RolePermissions",
                table: "RolePermissions",
                columns: new[] { "RoleId", "PermissionId" });

            migrationBuilder.AddPrimaryKey(
                name: "PK_RiskAssessments",
                table: "RiskAssessments",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_OperationLogs",
                table: "OperationLogs",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_LoginHistories",
                table: "LoginHistories",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_ExceptionLogs",
                table: "ExceptionLogs",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_AuditLogs",
                table: "AuditLogs",
                column: "Id");

            migrationBuilder.CreateIndex(
                name: "IX_workflow_tasks_AssigneeId",
                table: "workflow_tasks",
                column: "AssigneeId");

            migrationBuilder.CreateIndex(
                name: "IX_workflow_instances_WorkflowId",
                table: "workflow_instances",
                column: "WorkflowId");

            migrationBuilder.CreateIndex(
                name: "IX_media_files_CreatedBy",
                table: "media_files",
                column: "CreatedBy");

            migrationBuilder.CreateIndex(
                name: "IX_form_submissions_FormId",
                table: "form_submissions",
                column: "FormId");

            migrationBuilder.CreateIndex(
                name: "IX_categories_ParentId",
                table: "categories",
                column: "ParentId");

            migrationBuilder.CreateIndex(
                name: "IX_LoginHistories_UserId",
                table: "LoginHistories",
                column: "UserId");

            migrationBuilder.AddForeignKey(
                name: "FK_LoginHistories_users_UserId",
                table: "LoginHistories",
                column: "UserId",
                principalTable: "users",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_Publishes_content_items_ContentId",
                table: "Publishes",
                column: "ContentId",
                principalTable: "content_items",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_Publishes_users_UserId",
                table: "Publishes",
                column: "UserId",
                principalTable: "users",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_RolePermissions_permissions_PermissionId",
                table: "RolePermissions",
                column: "PermissionId",
                principalTable: "permissions",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_RolePermissions_roles_RoleId",
                table: "RolePermissions",
                column: "RoleId",
                principalTable: "roles",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_UserDevices_users_UserId",
                table: "UserDevices",
                column: "UserId",
                principalTable: "users",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_UserRoles_roles_RoleId",
                table: "UserRoles",
                column: "RoleId",
                principalTable: "roles",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_UserRoles_users_UserId",
                table: "UserRoles",
                column: "UserId",
                principalTable: "users",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_workflow_instances_Workflows_WorkflowId",
                table: "workflow_instances",
                column: "WorkflowId",
                principalTable: "Workflows",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
